package gatperdut.chato.core.interpreter.actions;

import gatperdut.chato.constants.CSConstantsCommandResult.CommandExecutionResult;
import gatperdut.chato.core.characters.BaseController;
import gatperdut.chato.core.interpreter.actions.generic.CommunicationAction;
import gatperdut.chato.core.interpreter.grammar.comminfo.CommunicationInfo;

public class TellAction extends CommunicationAction {

    public TellAction( CommunicationInfo info, BaseController entityController ) {
        super( info, entityController );
    }

    @Override
    public CommandExecutionResult perform() {
        checkForRunningCraft();

        if ( emptyEmote() ) {
            getEntityController().tx( "Empty emotes are not allowed." );
            return CommandExecutionResult.OK;
        }

        if ( invalidSpeech() ) {
            getEntityController().tx( "What do you want to tell?" );
            return CommandExecutionResult.OK;
        }

        if ( getInfo().getWhom() == null ) {
            getEntityController().tx( "Tell whom?" );
            return CommandExecutionResult.OK;
        }

        BaseController otherController = getEntityController().getRoomController().getCharactersController().getEntityController( getInfo().getWhom() );
        if ( otherController == null ) {
            getEntityController().tx( "You don't see that character here." );
            return CommandExecutionResult.OK;
        }

        String emote = getLastPartEmote();
        if ( emote == null ) {
            getEntityController().tx( "Check your emote." );
            return CommandExecutionResult.OK;
        }

        getEntityController().getEchoes().txTell( otherController, emote, getInfo().getSpeech() );

        return CommandExecutionResult.OK;

    }

}
